package com.example.mydy.model;

import java.util.Date;

/**
 * 广告模型类
 */
public class Advertisement {
    // 广告类基础属性
    private int id;
    private String title;
    private String description;
    private String imageUrl;
    private float reward;
    private String status;
    private String content;
    private String link;
    private Date createdAt;

    // 构造方法
    public Advertisement() {
        // 空构造函数
    }

    public Advertisement(int id, String title, String description, String imageUrl, float reward) {
        this.id = id;
        this.title = title;
        this.description = description;
        this.imageUrl = imageUrl;
        this.reward = reward;
    }

    public Advertisement(int id, String title, String description, String imageUrl, float reward, String content) {
        this.id = id;
        this.title = title;
        this.description = description;
        this.imageUrl = imageUrl;
        this.reward = reward;
        this.content = content;
    }

    public Advertisement(int id, String title, String content, String imageUrl, String link, Date createdAt) {
        this.id = id;
        this.title = title;
        this.content = content;
        this.imageUrl = imageUrl;
        this.link = link;
        this.createdAt = createdAt;
    }

    // Getter和Setter方法
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getImageUrl() {
        return imageUrl;
    }

    public void setImageUrl(String imageUrl) {
        this.imageUrl = imageUrl;
    }

    public float getReward() {
        return reward;
    }

    public void setReward(float reward) {
        this.reward = reward;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getLink() {
        return link;
    }

    public void setLink(String link) {
        this.link = link;
    }

    public Date getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(Date createdAt) {
        this.createdAt = createdAt;
    }

    // 兼容方法，用于接收字符串格式的创建时间
    public void setCreatedAt(String createdAtStr) {
        // 在实际应用中，应该解析日期字符串
        this.createdAt = new Date();
    }

    // 添加日期获取方法，返回字符串格式
    public String getDate() {
        if (createdAt == null) {
            return "";
        }
        
        // 使用 SimpleDateFormat 格式化为简短日期
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd", java.util.Locale.getDefault());
        return sdf.format(createdAt);
    }

    @Override
    public String toString() {
        return "Advertisement{" +
                "id=" + id +
                ", title='" + title + '\'' +
                ", description='" + description + '\'' +
                ", imageUrl='" + imageUrl + '\'' +
                ", reward=" + reward +
                ", status='" + status + '\'' +
                ", content='" + content + '\'' +
                ", link='" + link + '\'' +
                ", createdAt=" + createdAt +
                '}';
    }
}